Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

read android device serial number from sysfs node #547

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

vishwasudupa
Copy link

read android serial number value from sysfs node
instead of kernel command line. Upstream boot managers
e.g., systemd-boot does not populate kernel command line
with parameter androidboot.serialno.

Reading serial number from sysfs node
/sys/devices/soc0/serial_number generalizes the approach
and makes it independent of bootloader that loads kernel.

@lumag
Copy link
Collaborator

lumag commented Nov 17, 2023

Fix commit messages, please.

@lumag
Copy link
Collaborator

lumag commented Nov 17, 2023

Still not fully correct. Please take a note on the difference between your text and previous commit messages.

@@ -1,4 +1,4 @@
manufacturer=Qualcomm
model=`hostname`
androidserial="$(sed -n -e '/androidboot.serialno/ s/.*androidboot.serialno=\([^ ]*\).*/\1/gp ' /proc/cmdline)"
androidserial="$(printf "%x" "$(cat /sys/devices/soc0/serial_number)")"
Copy link
Collaborator

@lumag lumag Nov 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The serial number in sysfs doesn't match the serial number used by the bootloader and by Android. This makes using board farms extremely hard. You can no longer use a single serial number for the board.

E.g. on the db410c I checked sysfs reads 2644893864 = 0x9da5e0a8, while the bootloader sets androidboot.serialno=c2213c38 We should either find a way to convert sysfs data into the same serial number. Another option might be to make reading sysfs a fallback option for the case the /proc/cmdline doesn't contain serial number, but this still doesn't solve the problem of the board farms.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked both ABL and LK sources. The serial number is generated basing on the storage data rather than the SoC serial number. Could you please implement the same approach?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked on device and found the serial number used by the bootloader and value read from /sys/class/mmc_host/mmc0/mmc0:0001/serial are matching. Updated the patchset to use this instead of soc serial number.

@lumag
Copy link
Collaborator

lumag commented Nov 17, 2023

Also, what is Linux Build Service Account <lnxbuild@localhost>, that has committed this patch?

Read android serial number value from sysfs node
/sys/class/mmc_host/mmc0/mmc0:0001/serial instead of
 kernel command line.

Upstream boot managers e.g., systemd-boot does not populate
kernel command line with parameter androidboot.serialno.
This approach generalizes and makes serial number population
independent of bootloader that loads kernel.

Signed-off-by: Vishwas Udupa <[email protected]>
@vishwasudupa
Copy link
Author

Also, what is Linux Build Service Account <lnxbuild@localhost>, that has committed this patch?

Corrected committer-id.

@@ -1,4 +1,4 @@
manufacturer=Qualcomm
model=`hostname`
androidserial="$(sed -n -e '/androidboot.serialno/ s/.*androidboot.serialno=\([^ ]*\).*/\1/gp ' /proc/cmdline)"
androidserial="$(sed 's/0x//' /sys/class/mmc_host/mmc0/mmc0:0001/serial)"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will break for UFS-based devices.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @lumag

For the RB5, RB3 UFS devices you are using in which sysfs node you see the adb serial numbers matching?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to what I see in ABL sources, the serial number of the UFS-based boards is a CRC-32 of the UFS serial no.
For the reference, the RB5 that I have at hand:

# udevadm info /dev/sda | grep SERIAL
E: ID_SERIAL=2SAMSUNG
E: ID_SERIAL_SHORT=SAMSUNG
E: ID_SCSI_SERIAL=414b8c053f19
root@qcom-armv8a:~# xargs -n 1 < /proc/cmdline  | grep serial
androidboot.serialno=9105fd32

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Relevant piece from ABL:

  Status =
      gBS->HandleProtocol (HandleInfoList[0].Handle,
                           &gEfiMemCardInfoProtocolGuid, (VOID **)&CardInfo);
  if (Status != EFI_SUCCESS) {
    DEBUG ((EFI_D_ERROR, "Error locating MemCardInfoProtocol:%x\n", Status));
    return Status;
  }

  if (CardInfo->GetCardInfo (CardInfo, &CardInfoData) == EFI_SUCCESS) {
    if (Type == UFS) {
      Status = gBS->CalculateCrc32 (CardInfoData.product_serial_num,
                                    CardInfoData.serial_num_len, &SerialNo);
      if (Status != EFI_SUCCESS) {
        DEBUG ((EFI_D_ERROR,
                "Error calculating Crc of the unicode serial number: %x\n",
                Status));
        return Status;
      }
      AsciiSPrint (StrSerialNum, Len, "%x", SerialNo);
    } else {
      AsciiSPrint (StrSerialNum, Len, "%x",
                   *(UINT32 *)CardInfoData.product_serial_num);
    }

lumag

This comment was marked as duplicate.

Copy link
Collaborator

@lumag lumag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Please keep UFS devices working.
  2. Please make this more robust by checking that the the MMC device exists and that it is actually an eMMC device.

@vishwasudupa
Copy link
Author

Below pr solves the issue
#553

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants